﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Z1029.NoteEditor
{
    public class EventDataEditManager : MonoBehaviour
    {
        public static EventDataEditManager instance;
        public EventDataEditorCtrl ctl;
        public bool isEditing;

        public void ShowEventEditWindow(List<EventBase> es)
        {
            if (isEditing == true) CloseWindow();
            foreach (var item in es)
            {
                item.isEditing = true;
            }
            ctl.gameObject.active = true;
            ctl.window.SetWindowToFront();
            isEditing = true;
            ctl.selectEvents = es;
            ctl.multiSelect = true;
            ctl.Init();
        }

        public void ShowEventEditWindow(EventBase e)
        {
            if (isEditing == true) CloseWindow();
            e.isEditing = true;
            ctl.gameObject.active = true;
            ctl.window.SetWindowToFront();
            isEditing = true;
            ctl.selectEvent = e;
            ctl.multiSelect = false;
            ctl.Init();
        }

        public void CloseWindow()
        {

            if (ctl.multiSelect)
            {
                throw new System.NotImplementedException();
            }
            else
            {
                ctl.selectEvent.thisRenderer.color = (Color.white + Color.blue) / 2;
                ctl.selectEvent.isEditing = false;
                ctl.selectEvent = null;
            }
            ctl.gameObject.active = false;
            isEditing = false;
        }

        void Awake()
        {
            instance = this;
            ctl.gameObject.active = false;
            isEditing = false;
        }

        void Update()
        {

        }
    }
}